<?php
namespace Home\Controller\Senior;
use Think\Controller;

//后台管理员
class IndexController extends Controller
{
    /**
     * index 
     * 
     * 查看当前所有用户
     * @access public
     * @return void
     */
    public function index()
    {
        return $this->display('Senior/login');
    }

    /**
     * seniorLogin 
     * 
     * 超级管理员登录
     * @access public
     * @return void
     */
    public function seniorLogin()
    {
        //登录管理员
        if(IS_POST || IS_AJAX){
            $user = trim(I('POST.username'));
            $pwd = trim(I('POST.pwd'));

            $seniors = M('senior');
            $password = $seniors->where("name = '$user'")->getField('pwd');
            if(md5($pwd) === $password){
                cookie('username',$user,1800);//半小时失效
                cookie('pwd',$password,1800);//半小时失效
                cookie('class','admin',900);//15min失效,级别信息
                return redirect('/drm/');//鉴定ok,跳转管理员
            }
        }

        //没有密码用户直接跳转登录
        if(cookie('class' == null || cookie('username') ==null || cookie('pwd' == null))){
            //跳转管理员登录
            return $this->display('Senior/login');
        }
        return redirect('/drm/');
    }
}
